package cn.edu.scau.dao;

import cn.edu.scau.entity.NursingRecord;

import java.util.Date;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class NursingRecordSqlProvider {

    public String insertSelective(NursingRecord record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("nursingrecord");
        
        if (record.getNursingrecordid() != null) {
            sql.VALUES("nursingRecordID", "#{nursingrecordid,jdbcType=INTEGER}");
        }
        
        if (record.getNursingcontentid() != null) {
            sql.VALUES("nursingContentID", "#{nursingcontentid,jdbcType=INTEGER}");
        }
        
        if (record.getCustomerid() != null) {
            sql.VALUES("customerID", "#{customerid,jdbcType=INTEGER}");
        }
        
        if (record.getNurseid() != null) {
            sql.VALUES("nurseID", "#{nurseid,jdbcType=INTEGER}");
        }
        
        if (record.getNursingrecordtime() != null) {
            sql.VALUES("nursingRecordTime", "#{nursingrecordtime,jdbcType=TIMESTAMP}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(NursingRecord record) {
        SQL sql = new SQL();
        sql.UPDATE("nursingrecord");
        
        if (record.getNursingcontentid() != null) {
            sql.SET("nursingContentID = #{nursingcontentid,jdbcType=INTEGER}");
        }
        
        if (record.getCustomerid() != null) {
            sql.SET("customerID = #{customerid,jdbcType=INTEGER}");
        }
        
        if (record.getNurseid() != null) {
            sql.SET("nurseID = #{nurseid,jdbcType=INTEGER}");
        }
        
        if (record.getNursingrecordtime() != null) {
            sql.SET("nursingRecordTime = #{nursingrecordtime,jdbcType=TIMESTAMP}");
        }
        
        sql.WHERE("nursingRecordID = #{nursingrecordid,jdbcType=INTEGER}");
        
        return sql.toString();
    }
    
    public String findByPeriod(Date preTime,Date nextTime){
    	SQL sql = new SQL();
    	sql.SELECT("nursingrecordid,nursingcontentprojectname,customername,nursename,nursingrecordtime");
    	sql.FROM("((nursingrecord left join nursingcontent on nursingrecord.nursingContentID=nursingcontent.nursingContentID) left join customer on  nursingrecord.customerID=customer.customerID )left join nurse on nursingrecord.nurseID=nurse.nurseID");
    	if(preTime!=null&&nextTime!=null) {
    		sql.WHERE("nursingrecordtime between #{preTime} and #{nextTime}");
    	}
    	return sql.toString();
    }
}